package com.pktechan.api.utils;


import org.apache.commons.codec.binary.Base64;

/**
 * 小程序工具类
 * Created by kaifabu on 2018/9/11.
 */
public class MiniProgramUtil {
    /**
     * 解密数据
     *
     * @return
     * @throws Exception
     */
    public static String decrypt(String encryptedData, String sessionKey, String iv) {
        String result = "";
        try {
            byte[] resultByte = AESUtil.decrypt(Base64.decodeBase64(encryptedData), Base64.decodeBase64(sessionKey), Base64.decodeBase64(iv));
            if (null != resultByte && resultByte.length > 0) {
                result = new String(WxPKCS7Util.decode(resultByte), "utf-8");
            }
        } catch (Exception e) {
            result = "";
            e.printStackTrace();
        }
        return result;
    }
}
